package com.scisoft.scan.control.stock;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.scisoft.scan.dy.R;
import com.scisoft.scan.data.stock.StockFlowDetailBean;

import java.util.List;

public class StockFlowAdapter extends BaseAdapter {
    private List<StockFlowDetailBean> stockFlowDetailBeanList;//数据源
    private LayoutInflater mInflater;//布局装载器对象

    public StockFlowAdapter(List<StockFlowDetailBean> stockFlowDetailBeanList, Context context) {
        this.stockFlowDetailBeanList = stockFlowDetailBeanList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        //return返回的是int类型，也就是页面要显示的数量。
        return stockFlowDetailBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return stockFlowDetailBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_stockflow, null);
        }
        TextView tv_fss = convertView.findViewById(R.id.tv_fss);
        TextView tv_jcs = convertView.findViewById(R.id.tv_jcs);
        TextView tv_jce = convertView.findViewById(R.id.tv_jce);
        TextView tv_orderType = convertView.findViewById(R.id.tv_orderType);
        TextView tv_orderNo = convertView.findViewById(R.id.tv_orderNo);
        TextView tv_orderDate = convertView.findViewById(R.id.tv_orderDate);
        //获取相应索引的ItemBean对象
        StockFlowDetailBean bean = stockFlowDetailBeanList.get(position);
        //设置控件的对应属性值
        tv_fss.setText(String.valueOf(bean.fss));
        tv_jcs.setText(String.valueOf(bean.jcs));
        tv_jce.setText(String.valueOf(bean.jce));
        tv_orderType.setText(bean.orderTypeName);
        tv_orderNo.setText(bean.orderNo);
        tv_orderDate.setText(bean.orderDate);
        return convertView;
    }
}
